using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using iTextSharp.text.pdf;
using System.IO;
using System.Diagnostics;

namespace ExpenseIt
{
    public partial class planOfCare : Page
    {
        public planOfCare()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {

            var pathOfExe = System.AppDomain.CurrentDomain.BaseDirectory;
            var relativeToExe = pathOfExe + "SWMPDD_POC_Revised_10-03-2012_Form_V.2.03_Extended_4.pdf";
            PdfReader reader = new PdfReader(relativeToExe);
            reader.RemoveUsageRights();
            PdfStamper stamper = new PdfStamper(reader, new FileStream(pathOfExe + "filled.pdf", FileMode.Create), '\0', true);
            AcroFields form = stamper.AcroFields;

            foreach (TextBox textbox in planOfCareGrid.Children.OfType<TextBox>())
            {
                string txtBx = textbox.Name;
                form.SetField(txtBx, textbox.Text);
            }

            foreach (CheckBox checkbox in planOfCareGrid.Children.OfType<CheckBox>().Where(cb => cb.IsChecked == true))
            {
                string CckBx = checkbox.Name;
                form.SetField(CckBx, "1");
            }
            foreach (ComboBox comboBox in planOfCareGrid.Children.OfType<ComboBox>())
            {
                string CmbBx = comboBox.Name;
                form.SetField(CmbBx, comboBox.SelectionBoxItem.ToString());
            }
            stamper.Close();
            System.Diagnostics.Process.Start(@pathOfExe + "filled.pdf");
        }

        private void MenuItemHVF(object sender, RoutedEventArgs e)
        {
            caseMngHomeVisitReport CMHVRPage = new caseMngHomeVisitReport();
            this.NavigationService.Navigate(CMHVRPage);
        }
        private void MenuItemPOC(object sender, RoutedEventArgs e)
        {
            planOfCare POCPage = new planOfCare();
            this.NavigationService.Navigate(POCPage);
        }
      
        /*foreach (CheckBox checkbox in panel.Children.OfType<CheckBox>().Where( cb => cb.IsChecked == true))
            {
                listbox.Items.Add(checkbox.Name);
            }*/
        }
}
